Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reqwest with http and hyper. #294

Closed
wants to merge 8 commits into from
Closed

Replace reqwest with http and hyper. #294

wants to merge 8 commits into from

Conversation

IgnisDa
Copy link

@IgnisDa IgnisDa commented Jan 13, 2023

Fixes #99.

src/lib.rs Outdated Show resolved Hide resolved
Comment on lines -316 to -317
pub fn base_url(mut self, base_url: impl reqwest::IntoUrl) -> Result<Self> {
self.base_url = Some(base_url.into_url().context(crate::error::HttpSnafu)?);
Copy link
Owner

@XAMPPRocky XAMPPRocky Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use TryInto<Url> instead of AsRef, because then we can still accept Url in addition to &str.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the docs: https://doc.rust-lang.org/std/convert/trait.TryInto.html

Library authors should usually not directly implement this trait, but should prefer implementing the TryFrom trait, which offers greater flexibility and provides an equivalent TryInto implementation for free, thanks to a blanket implementation in the standard library.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that documentation is for implementing TryInto (e.g. impl TryInto<Url> for str {}), you don't implement TryInto, because all TryFrom implementations automatically implement TryInto, but you can still use TryInto where appropriate, otherwise the traits wouldn't be very useful. 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you can still use TryInto where appropriate

Can you tell the syntax to this please?

Copy link
Owner

@XAMPPRocky XAMPPRocky Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same as what you did for AsRef<str>.

fn foo(url: impl TryInto<Url>) -> Result<()> {
     let url = url.try_into()?;
     Ok(())
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use it, however I could not get the types to match up.

@L1ghtman2k
Copy link
Contributor

L1ghtman2k commented Jan 13, 2023

What a coincidence, we were actually just getting started with implementing tower/hyper/http for octocrab. I will likely make a separate PR for this, and we can compare/merge best of both PRs

@IgnisDa
Copy link
Author

IgnisDa commented Jan 14, 2023

@L1ghtman2k If you'd like, you can edit this PR. I don't think I'll be able to do the hyper integration; it's too complicated for me. I'm more than happy to add you as a contributor to my fork.

@L1ghtman2k
Copy link
Contributor

@L1ghtman2k If you'd like, you can edit this PR. I don't think I'll be able to do the hyper integration; it's too complicated for me. I'm more than happy to add you as a contributor to my fork.

Hey, it is definitely ambitious, I am myself am relatively new to rust, will see how far I can get. No need to give access, I have already cherry picked some of your changes

@XAMPPRocky
Copy link
Owner

The hyper integration should be straightforward, it's replacing reqwest::Client with a dynamic tower::Service, look at the kube crate for inspiration. https://github.com/kube-rs/kube/blob/ce69d9238c4dcd65b50f7647f485922169ab078d/kube-client/src/client/mod.rs#L65

@IgnisDa
Copy link
Author

IgnisDa commented Jan 19, 2023

@L1ghtman2k Any progress made on this?

@L1ghtman2k
Copy link
Contributor

@L1ghtman2k Any progress made on this?

Yes, I am working on it here: #297 (still need to wrap few things before it is ready for review)

@IgnisDa
Copy link
Author

IgnisDa commented Jan 19, 2023

Awesome! Closing this in favor of #297.

@IgnisDa IgnisDa closed this Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace reqwest with http
3 participants